#include "modem_rf_le501x_24g.h"
#include "reg_rcc.h"
#include "field_manipulate.h"
#include "reg_rf.h"
#include "reg_mdm2.h"
#include "reg_syscfg.h"
#include "platform.h"
#include "ls_dbg.h"
#include "ls_24g.h"
#include "log.h"

#define BAND_DI_S_TX(freq) (((freq)-129*16)/16)
#define BAND_FRAC_TX(freq) (((freq)-129*16)%16)*(1<<20)

#define BAND_RX_RF_PLL(freq) (((((float)(freq)-2)*8.0)/9.0)/16.0-129)
// #define BAND_DI_S_RX(freq) BAND_DI_S_TX(((((freq)-2)*8)/9))
#define BAND_DI_S_RX(freq) ((uint32_t)(BAND_RX_RF_PLL(freq)))
#define BAND_FRAC_RX(freq) ((uint32_t)((BAND_RX_RF_PLL(freq)-BAND_DI_S_RX(freq))*(1<<24)))


#define RF_GAIN_TBL_SIZE           (8)
#define RF_PWR_TBL_SIZE            (8)

#define PLL_GAIN_CAL_FRQ_DIS0  20

// from 2360 to 2510
static const uint8_t tx_di_s_array[] = {
    BAND_DI_S_TX(2350), BAND_DI_S_TX(2351), BAND_DI_S_TX(2352), BAND_DI_S_TX(2353), BAND_DI_S_TX(2354), BAND_DI_S_TX(2355), BAND_DI_S_TX(2356), BAND_DI_S_TX(2357), BAND_DI_S_TX(2358), BAND_DI_S_TX(2359),
    BAND_DI_S_TX(2360), BAND_DI_S_TX(2361), BAND_DI_S_TX(2362), BAND_DI_S_TX(2363), BAND_DI_S_TX(2364), BAND_DI_S_TX(2365), BAND_DI_S_TX(2366), BAND_DI_S_TX(2367), BAND_DI_S_TX(2368), BAND_DI_S_TX(2369),
    BAND_DI_S_TX(2370), BAND_DI_S_TX(2371), BAND_DI_S_TX(2372), BAND_DI_S_TX(2373), BAND_DI_S_TX(2374), BAND_DI_S_TX(2375), BAND_DI_S_TX(2376), BAND_DI_S_TX(2377), BAND_DI_S_TX(2378), BAND_DI_S_TX(2379),
    BAND_DI_S_TX(2380), BAND_DI_S_TX(2381), BAND_DI_S_TX(2382), BAND_DI_S_TX(2383), BAND_DI_S_TX(2384), BAND_DI_S_TX(2385), BAND_DI_S_TX(2386), BAND_DI_S_TX(2387), BAND_DI_S_TX(2388), BAND_DI_S_TX(2389),
    BAND_DI_S_TX(2390), BAND_DI_S_TX(2391), BAND_DI_S_TX(2392), BAND_DI_S_TX(2393), BAND_DI_S_TX(2394), BAND_DI_S_TX(2395), BAND_DI_S_TX(2396), BAND_DI_S_TX(2397), BAND_DI_S_TX(2398), BAND_DI_S_TX(2399),
    BAND_DI_S_TX(2400), BAND_DI_S_TX(2401), BAND_DI_S_TX(2402), BAND_DI_S_TX(2403), BAND_DI_S_TX(2404), BAND_DI_S_TX(2405), BAND_DI_S_TX(2406), BAND_DI_S_TX(2407), BAND_DI_S_TX(2408), BAND_DI_S_TX(2409),
    BAND_DI_S_TX(2410), BAND_DI_S_TX(2411), BAND_DI_S_TX(2412), BAND_DI_S_TX(2413), BAND_DI_S_TX(2414), BAND_DI_S_TX(2415), BAND_DI_S_TX(2416), BAND_DI_S_TX(2417), BAND_DI_S_TX(2418), BAND_DI_S_TX(2419),
    BAND_DI_S_TX(2420), BAND_DI_S_TX(2421), BAND_DI_S_TX(2422), BAND_DI_S_TX(2423), BAND_DI_S_TX(2424), BAND_DI_S_TX(2425), BAND_DI_S_TX(2426), BAND_DI_S_TX(2427), BAND_DI_S_TX(2428), BAND_DI_S_TX(2429),
    BAND_DI_S_TX(2430), BAND_DI_S_TX(2431), BAND_DI_S_TX(2432), BAND_DI_S_TX(2433), BAND_DI_S_TX(2434), BAND_DI_S_TX(2435), BAND_DI_S_TX(2436), BAND_DI_S_TX(2437), BAND_DI_S_TX(2438), BAND_DI_S_TX(2439),
    BAND_DI_S_TX(2440), BAND_DI_S_TX(2441), BAND_DI_S_TX(2442), BAND_DI_S_TX(2443), BAND_DI_S_TX(2444), BAND_DI_S_TX(2445), BAND_DI_S_TX(2446), BAND_DI_S_TX(2447), BAND_DI_S_TX(2448), BAND_DI_S_TX(2449),
    BAND_DI_S_TX(2450), BAND_DI_S_TX(2451), BAND_DI_S_TX(2452), BAND_DI_S_TX(2453), BAND_DI_S_TX(2454), BAND_DI_S_TX(2455), BAND_DI_S_TX(2456), BAND_DI_S_TX(2457), BAND_DI_S_TX(2458), BAND_DI_S_TX(2459),
    BAND_DI_S_TX(2460), BAND_DI_S_TX(2461), BAND_DI_S_TX(2462), BAND_DI_S_TX(2463), BAND_DI_S_TX(2464), BAND_DI_S_TX(2465), BAND_DI_S_TX(2466), BAND_DI_S_TX(2467), BAND_DI_S_TX(2468), BAND_DI_S_TX(2469),
    BAND_DI_S_TX(2470), BAND_DI_S_TX(2471), BAND_DI_S_TX(2472), BAND_DI_S_TX(2473), BAND_DI_S_TX(2474), BAND_DI_S_TX(2475), BAND_DI_S_TX(2476), BAND_DI_S_TX(2477), BAND_DI_S_TX(2478), BAND_DI_S_TX(2479),
    BAND_DI_S_TX(2480), BAND_DI_S_TX(2481), BAND_DI_S_TX(2482), BAND_DI_S_TX(2483), BAND_DI_S_TX(2484), BAND_DI_S_TX(2485), BAND_DI_S_TX(2486), BAND_DI_S_TX(2487), BAND_DI_S_TX(2488), BAND_DI_S_TX(2489),
    BAND_DI_S_TX(2490), BAND_DI_S_TX(2491), BAND_DI_S_TX(2492), BAND_DI_S_TX(2493), BAND_DI_S_TX(2494), BAND_DI_S_TX(2495), BAND_DI_S_TX(2496), BAND_DI_S_TX(2497), BAND_DI_S_TX(2498), BAND_DI_S_TX(2499),
    BAND_DI_S_TX(2500), BAND_DI_S_TX(2501), BAND_DI_S_TX(2502), BAND_DI_S_TX(2503), BAND_DI_S_TX(2504), BAND_DI_S_TX(2505), BAND_DI_S_TX(2506), BAND_DI_S_TX(2507), BAND_DI_S_TX(2508), BAND_DI_S_TX(2509),
    BAND_DI_S_TX(2510), BAND_DI_S_TX(2511)
};
static const uint32_t tx_frac_array[] = {
    BAND_FRAC_TX(2350), BAND_FRAC_TX(2351), BAND_FRAC_TX(2352), BAND_FRAC_TX(2353), BAND_FRAC_TX(2354), BAND_FRAC_TX(2355), BAND_FRAC_TX(2356), BAND_FRAC_TX(2357), BAND_FRAC_TX(2358), BAND_FRAC_TX(2359),
    BAND_FRAC_TX(2360), BAND_FRAC_TX(2361), BAND_FRAC_TX(2362), BAND_FRAC_TX(2363), BAND_FRAC_TX(2364), BAND_FRAC_TX(2365), BAND_FRAC_TX(2366), BAND_FRAC_TX(2367), BAND_FRAC_TX(2368), BAND_FRAC_TX(2369),
    BAND_FRAC_TX(2370), BAND_FRAC_TX(2371), BAND_FRAC_TX(2372), BAND_FRAC_TX(2373), BAND_FRAC_TX(2374), BAND_FRAC_TX(2375), BAND_FRAC_TX(2376), BAND_FRAC_TX(2377), BAND_FRAC_TX(2378), BAND_FRAC_TX(2379),
    BAND_FRAC_TX(2380), BAND_FRAC_TX(2381), BAND_FRAC_TX(2382), BAND_FRAC_TX(2383), BAND_FRAC_TX(2384), BAND_FRAC_TX(2385), BAND_FRAC_TX(2386), BAND_FRAC_TX(2387), BAND_FRAC_TX(2388), BAND_FRAC_TX(2389),
    BAND_FRAC_TX(2390), BAND_FRAC_TX(2391), BAND_FRAC_TX(2392), BAND_FRAC_TX(2393), BAND_FRAC_TX(2394), BAND_FRAC_TX(2395), BAND_FRAC_TX(2396), BAND_FRAC_TX(2397), BAND_FRAC_TX(2398), BAND_FRAC_TX(2399),
    BAND_FRAC_TX(2400), BAND_FRAC_TX(2401), BAND_FRAC_TX(2402), BAND_FRAC_TX(2403), BAND_FRAC_TX(2404), BAND_FRAC_TX(2405), BAND_FRAC_TX(2406), BAND_FRAC_TX(2407), BAND_FRAC_TX(2408), BAND_FRAC_TX(2409),
    BAND_FRAC_TX(2410), BAND_FRAC_TX(2411), BAND_FRAC_TX(2412), BAND_FRAC_TX(2413), BAND_FRAC_TX(2414), BAND_FRAC_TX(2415), BAND_FRAC_TX(2416), BAND_FRAC_TX(2417), BAND_FRAC_TX(2418), BAND_FRAC_TX(2419),
    BAND_FRAC_TX(2420), BAND_FRAC_TX(2421), BAND_FRAC_TX(2422), BAND_FRAC_TX(2423), BAND_FRAC_TX(2424), BAND_FRAC_TX(2425), BAND_FRAC_TX(2426), BAND_FRAC_TX(2427), BAND_FRAC_TX(2428), BAND_FRAC_TX(2429),
    BAND_FRAC_TX(2430), BAND_FRAC_TX(2431), BAND_FRAC_TX(2432), BAND_FRAC_TX(2433), BAND_FRAC_TX(2434), BAND_FRAC_TX(2435), BAND_FRAC_TX(2436), BAND_FRAC_TX(2437), BAND_FRAC_TX(2438), BAND_FRAC_TX(2439),
    BAND_FRAC_TX(2440), BAND_FRAC_TX(2441), BAND_FRAC_TX(2442), BAND_FRAC_TX(2443), BAND_FRAC_TX(2444), BAND_FRAC_TX(2445), BAND_FRAC_TX(2446), BAND_FRAC_TX(2447), BAND_FRAC_TX(2448), BAND_FRAC_TX(2449),
    BAND_FRAC_TX(2450), BAND_FRAC_TX(2451), BAND_FRAC_TX(2452), BAND_FRAC_TX(2453), BAND_FRAC_TX(2454), BAND_FRAC_TX(2455), BAND_FRAC_TX(2456), BAND_FRAC_TX(2457), BAND_FRAC_TX(2458), BAND_FRAC_TX(2459),
    BAND_FRAC_TX(2460), BAND_FRAC_TX(2461), BAND_FRAC_TX(2462), BAND_FRAC_TX(2463), BAND_FRAC_TX(2464), BAND_FRAC_TX(2465), BAND_FRAC_TX(2466), BAND_FRAC_TX(2467), BAND_FRAC_TX(2468), BAND_FRAC_TX(2469),
    BAND_FRAC_TX(2470), BAND_FRAC_TX(2471), BAND_FRAC_TX(2472), BAND_FRAC_TX(2473), BAND_FRAC_TX(2474), BAND_FRAC_TX(2475), BAND_FRAC_TX(2476), BAND_FRAC_TX(2477), BAND_FRAC_TX(2478), BAND_FRAC_TX(2479),
    BAND_FRAC_TX(2480), BAND_FRAC_TX(2481), BAND_FRAC_TX(2482), BAND_FRAC_TX(2483), BAND_FRAC_TX(2484), BAND_FRAC_TX(2485), BAND_FRAC_TX(2486), BAND_FRAC_TX(2487), BAND_FRAC_TX(2488), BAND_FRAC_TX(2489),
    BAND_FRAC_TX(2490), BAND_FRAC_TX(2491), BAND_FRAC_TX(2492), BAND_FRAC_TX(2493), BAND_FRAC_TX(2494), BAND_FRAC_TX(2495), BAND_FRAC_TX(2496), BAND_FRAC_TX(2497), BAND_FRAC_TX(2498), BAND_FRAC_TX(2499),
    BAND_FRAC_TX(2500), BAND_FRAC_TX(2501), BAND_FRAC_TX(2502), BAND_FRAC_TX(2503), BAND_FRAC_TX(2504), BAND_FRAC_TX(2505), BAND_FRAC_TX(2506), BAND_FRAC_TX(2507), BAND_FRAC_TX(2508), BAND_FRAC_TX(2509),
    BAND_FRAC_TX(2510), BAND_FRAC_TX(2511)
};
static const uint8_t rx_di_s_array[] = {
    BAND_DI_S_RX(2350), BAND_DI_S_RX(2351), BAND_DI_S_RX(2352), BAND_DI_S_RX(2353), BAND_DI_S_RX(2354), BAND_DI_S_RX(2355), BAND_DI_S_RX(2356), BAND_DI_S_RX(2357), BAND_DI_S_RX(2358), BAND_DI_S_RX(2359),
    BAND_DI_S_RX(2360), BAND_DI_S_RX(2361), BAND_DI_S_RX(2362), BAND_DI_S_RX(2363), BAND_DI_S_RX(2364), BAND_DI_S_RX(2365), BAND_DI_S_RX(2366), BAND_DI_S_RX(2367), BAND_DI_S_RX(2368), BAND_DI_S_RX(2369),
    BAND_DI_S_RX(2370), BAND_DI_S_RX(2371), BAND_DI_S_RX(2372), BAND_DI_S_RX(2373), BAND_DI_S_RX(2374), BAND_DI_S_RX(2375), BAND_DI_S_RX(2376), BAND_DI_S_RX(2377), BAND_DI_S_RX(2378), BAND_DI_S_RX(2379),
    BAND_DI_S_RX(2380), BAND_DI_S_RX(2381), BAND_DI_S_RX(2382), BAND_DI_S_RX(2383), BAND_DI_S_RX(2384), BAND_DI_S_RX(2385), BAND_DI_S_RX(2386), BAND_DI_S_RX(2387), BAND_DI_S_RX(2388), BAND_DI_S_RX(2389),
    BAND_DI_S_RX(2390), BAND_DI_S_RX(2391), BAND_DI_S_RX(2392), BAND_DI_S_RX(2393), BAND_DI_S_RX(2394), BAND_DI_S_RX(2395), BAND_DI_S_RX(2396), BAND_DI_S_RX(2397), BAND_DI_S_RX(2398), BAND_DI_S_RX(2399),
    BAND_DI_S_RX(2400), BAND_DI_S_RX(2401), BAND_DI_S_RX(2402), BAND_DI_S_RX(2403), BAND_DI_S_RX(2404), BAND_DI_S_RX(2405), BAND_DI_S_RX(2406), BAND_DI_S_RX(2407), BAND_DI_S_RX(2408), BAND_DI_S_RX(2409),
    BAND_DI_S_RX(2410), BAND_DI_S_RX(2411), BAND_DI_S_RX(2412), BAND_DI_S_RX(2413), BAND_DI_S_RX(2414), BAND_DI_S_RX(2415), BAND_DI_S_RX(2416), BAND_DI_S_RX(2417), BAND_DI_S_RX(2418), BAND_DI_S_RX(2419),
    BAND_DI_S_RX(2420), BAND_DI_S_RX(2421), BAND_DI_S_RX(2422), BAND_DI_S_RX(2423), BAND_DI_S_RX(2424), BAND_DI_S_RX(2425), BAND_DI_S_RX(2426), BAND_DI_S_RX(2427), BAND_DI_S_RX(2428), BAND_DI_S_RX(2429),
    BAND_DI_S_RX(2430), BAND_DI_S_RX(2431), BAND_DI_S_RX(2432), BAND_DI_S_RX(2433), BAND_DI_S_RX(2434), BAND_DI_S_RX(2435), BAND_DI_S_RX(2436), BAND_DI_S_RX(2437), BAND_DI_S_RX(2438), BAND_DI_S_RX(2439),
    BAND_DI_S_RX(2440), BAND_DI_S_RX(2441), BAND_DI_S_RX(2442), BAND_DI_S_RX(2443), BAND_DI_S_RX(2444), BAND_DI_S_RX(2445), BAND_DI_S_RX(2446), BAND_DI_S_RX(2447), BAND_DI_S_RX(2448), BAND_DI_S_RX(2449),
    BAND_DI_S_RX(2450), BAND_DI_S_RX(2451), BAND_DI_S_RX(2452), BAND_DI_S_RX(2453), BAND_DI_S_RX(2454), BAND_DI_S_RX(2455), BAND_DI_S_RX(2456), BAND_DI_S_RX(2457), BAND_DI_S_RX(2458), BAND_DI_S_RX(2459),
    BAND_DI_S_RX(2460), BAND_DI_S_RX(2461), BAND_DI_S_RX(2462), BAND_DI_S_RX(2463), BAND_DI_S_RX(2464), BAND_DI_S_RX(2465), BAND_DI_S_RX(2466), BAND_DI_S_RX(2467), BAND_DI_S_RX(2468), BAND_DI_S_RX(2469),
    BAND_DI_S_RX(2470), BAND_DI_S_RX(2471), BAND_DI_S_RX(2472), BAND_DI_S_RX(2473), BAND_DI_S_RX(2474), BAND_DI_S_RX(2475), BAND_DI_S_RX(2476), BAND_DI_S_RX(2477), BAND_DI_S_RX(2478), BAND_DI_S_RX(2479),
    BAND_DI_S_RX(2480), BAND_DI_S_RX(2481), BAND_DI_S_RX(2482), BAND_DI_S_RX(2483), BAND_DI_S_RX(2484), BAND_DI_S_RX(2485), BAND_DI_S_RX(2486), BAND_DI_S_RX(2487), BAND_DI_S_RX(2488), BAND_DI_S_RX(2489),
    BAND_DI_S_RX(2490), BAND_DI_S_RX(2491), BAND_DI_S_RX(2492), BAND_DI_S_RX(2493), BAND_DI_S_RX(2494), BAND_DI_S_RX(2495), BAND_DI_S_RX(2496), BAND_DI_S_RX(2497), BAND_DI_S_RX(2498), BAND_DI_S_RX(2499),
    BAND_DI_S_RX(2500), BAND_DI_S_RX(2501), BAND_DI_S_RX(2502), BAND_DI_S_RX(2503), BAND_DI_S_RX(2504), BAND_DI_S_RX(2505), BAND_DI_S_RX(2506), BAND_DI_S_RX(2507), BAND_DI_S_RX(2508), BAND_DI_S_RX(2509),
    BAND_DI_S_RX(2510), BAND_DI_S_RX(2511)
};
static const uint32_t rx_frac_array[] = {
    BAND_FRAC_RX(2350), BAND_FRAC_RX(2351), BAND_FRAC_RX(2352), BAND_FRAC_RX(2353), BAND_FRAC_RX(2354), BAND_FRAC_RX(2355), BAND_FRAC_RX(2356), BAND_FRAC_RX(2357), BAND_FRAC_RX(2358), BAND_FRAC_RX(2359),
    BAND_FRAC_RX(2360), BAND_FRAC_RX(2361), BAND_FRAC_RX(2362), BAND_FRAC_RX(2363), BAND_FRAC_RX(2364), BAND_FRAC_RX(2365), BAND_FRAC_RX(2366), BAND_FRAC_RX(2367), BAND_FRAC_RX(2368), BAND_FRAC_RX(2369),
    BAND_FRAC_RX(2370), BAND_FRAC_RX(2371), BAND_FRAC_RX(2372), BAND_FRAC_RX(2373), BAND_FRAC_RX(2374), BAND_FRAC_RX(2375), BAND_FRAC_RX(2376), BAND_FRAC_RX(2377), BAND_FRAC_RX(2378), BAND_FRAC_RX(2379),
    BAND_FRAC_RX(2380), BAND_FRAC_RX(2381), BAND_FRAC_RX(2382), BAND_FRAC_RX(2383), BAND_FRAC_RX(2384), BAND_FRAC_RX(2385), BAND_FRAC_RX(2386), BAND_FRAC_RX(2387), BAND_FRAC_RX(2388), BAND_FRAC_RX(2389),
    BAND_FRAC_RX(2390), BAND_FRAC_RX(2391), BAND_FRAC_RX(2392), BAND_FRAC_RX(2393), BAND_FRAC_RX(2394), BAND_FRAC_RX(2395), BAND_FRAC_RX(2396), BAND_FRAC_RX(2397), BAND_FRAC_RX(2398), BAND_FRAC_RX(2399),
    BAND_FRAC_RX(2400), BAND_FRAC_RX(2401), BAND_FRAC_RX(2402), BAND_FRAC_RX(2403), BAND_FRAC_RX(2404), BAND_FRAC_RX(2405), BAND_FRAC_RX(2406), BAND_FRAC_RX(2407), BAND_FRAC_RX(2408), BAND_FRAC_RX(2409),
    BAND_FRAC_RX(2410), BAND_FRAC_RX(2411), BAND_FRAC_RX(2412), BAND_FRAC_RX(2413), BAND_FRAC_RX(2414), BAND_FRAC_RX(2415), BAND_FRAC_RX(2416), BAND_FRAC_RX(2417), BAND_FRAC_RX(2418), BAND_FRAC_RX(2419),
    BAND_FRAC_RX(2420), BAND_FRAC_RX(2421), BAND_FRAC_RX(2422), BAND_FRAC_RX(2423), BAND_FRAC_RX(2424), BAND_FRAC_RX(2425), BAND_FRAC_RX(2426), BAND_FRAC_RX(2427), BAND_FRAC_RX(2428), BAND_FRAC_RX(2429),
    BAND_FRAC_RX(2430), BAND_FRAC_RX(2431), BAND_FRAC_RX(2432), BAND_FRAC_RX(2433), BAND_FRAC_RX(2434), BAND_FRAC_RX(2435), BAND_FRAC_RX(2436), BAND_FRAC_RX(2437), BAND_FRAC_RX(2438), BAND_FRAC_RX(2439),
    BAND_FRAC_RX(2440), BAND_FRAC_RX(2441), BAND_FRAC_RX(2442), BAND_FRAC_RX(2443), BAND_FRAC_RX(2444), BAND_FRAC_RX(2445), BAND_FRAC_RX(2446), BAND_FRAC_RX(2447), BAND_FRAC_RX(2448), BAND_FRAC_RX(2449),
    BAND_FRAC_RX(2450), BAND_FRAC_RX(2451), BAND_FRAC_RX(2452), BAND_FRAC_RX(2453), BAND_FRAC_RX(2454), BAND_FRAC_RX(2455), BAND_FRAC_RX(2456), BAND_FRAC_RX(2457), BAND_FRAC_RX(2458), BAND_FRAC_RX(2459),
    BAND_FRAC_RX(2460), BAND_FRAC_RX(2461), BAND_FRAC_RX(2462), BAND_FRAC_RX(2463), BAND_FRAC_RX(2464), BAND_FRAC_RX(2465), BAND_FRAC_RX(2466), BAND_FRAC_RX(2467), BAND_FRAC_RX(2468), BAND_FRAC_RX(2469),
    BAND_FRAC_RX(2470), BAND_FRAC_RX(2471), BAND_FRAC_RX(2472), BAND_FRAC_RX(2473), BAND_FRAC_RX(2474), BAND_FRAC_RX(2475), BAND_FRAC_RX(2476), BAND_FRAC_RX(2477), BAND_FRAC_RX(2478), BAND_FRAC_RX(2479),
    BAND_FRAC_RX(2480), BAND_FRAC_RX(2481), BAND_FRAC_RX(2482), BAND_FRAC_RX(2483), BAND_FRAC_RX(2484), BAND_FRAC_RX(2485), BAND_FRAC_RX(2486), BAND_FRAC_RX(2487), BAND_FRAC_RX(2488), BAND_FRAC_RX(2489),
    BAND_FRAC_RX(2490), BAND_FRAC_RX(2491), BAND_FRAC_RX(2492), BAND_FRAC_RX(2493), BAND_FRAC_RX(2494), BAND_FRAC_RX(2495), BAND_FRAC_RX(2496), BAND_FRAC_RX(2497), BAND_FRAC_RX(2498), BAND_FRAC_RX(2499),
    BAND_FRAC_RX(2500), BAND_FRAC_RX(2501), BAND_FRAC_RX(2502), BAND_FRAC_RX(2503), BAND_FRAC_RX(2504), BAND_FRAC_RX(2505), BAND_FRAC_RX(2506), BAND_FRAC_RX(2507), BAND_FRAC_RX(2508), BAND_FRAC_RX(2509),
    BAND_FRAC_RX(2510), BAND_FRAC_RX(2511)
};
static uint8_t   pll_int_vtxd_ext_24g;
// struct {
//     uint8_t ldo_tx_trim:3,
//             ldo_rx_trim:3;
// }rf_ret;

#define RF_POWER_MAX                0x4
#define RF_POWER_MIN                0

static void rf_reg_init_24g(void)
{
    RF->REG00 = FIELD_BUILD(RF_EN_DAC_DIG_PWR, 1)
               | FIELD_BUILD(RF_EN_AGC_PWR, 1)
               | FIELD_BUILD(RF_EN_PLL_SDM, 1)
               | FIELD_BUILD(RF_EN_ADC_DIG, 1)
               | FIELD_BUILD(RF_EN_LDO_PAHP, 1)
               | FIELD_BUILD(RF_EN_LDO_PLL, 1)
               | FIELD_BUILD(RF_EN_LDO_VCO, 1)
               | FIELD_BUILD(RF_EN_LDO_PA, 1)
               | FIELD_BUILD(RF_EN_LDO_IF, 1)
               | FIELD_BUILD(RF_EN_LDO_TX, 1)
               | FIELD_BUILD(RF_EN_LDO_RX, 1)
               | FIELD_BUILD(RF_EN_LDO_PAHP_BYPS, 0)
               | FIELD_BUILD(RF_EN_PAHP, 1)
               | FIELD_BUILD(RF_EN_DAC_ZB, 0)
               | FIELD_BUILD(RF_EN_DAC_BLE, 0)//
               | FIELD_BUILD(RF_EN_PA_STG2, 1)
               | FIELD_BUILD(RF_EN_PA_STG1, 1)
               | FIELD_BUILD(RF_EN_PA, 1)
               | FIELD_BUILD(RF_EN_PLL, 1)
               | FIELD_BUILD(RF_EN_AGC, 0)
               | FIELD_BUILD(RF_EN_ADC, 0)
               | FIELD_BUILD(RF_EN_LMT_RSSI, 0)
               | FIELD_BUILD(RF_EN_BPF, 0)
               | FIELD_BUILD(RF_EN_MIXL, 0)
               | FIELD_BUILD(RF_EN_MIXH, 0)
               | FIELD_BUILD(RF_EN_LNA, 0);
   RF->REG04 = FIELD_BUILD(RF_LNA_VB_ADJ,7)
               | FIELD_BUILD(RF_LNA_TANK_TUNE,1)
               | FIELD_BUILD(RF_LNA_R_ADJ,0)
               | FIELD_BUILD(RF_MIXL_BIAS_CTL,3)
               | FIELD_BUILD(RF_MIXL_BIAS_SEL,0)
               | FIELD_BUILD(RF_MIXH_BIAS_CTL,3)
               | FIELD_BUILD(RF_MIXH_BIAS_SEL,0)
               | FIELD_BUILD(RF_BPF_CAL_CODE_EXT,0x1F)
               | FIELD_BUILD(RF_BPF_CAL_CODE_EXT_EN,1)
               | FIELD_BUILD(RF_BPF_CAL_EN,0)
               | FIELD_BUILD(RF_EN_LNA_BYPS,0)
               | FIELD_BUILD(RF_LNA_GAIN,0)
               | FIELD_BUILD(RF_MIXL_GAIN_CTL,0)
               | FIELD_BUILD(RF_MIXH_GAIN_CTL,0)
               | FIELD_BUILD(RF_BPF_GAIN_ADJ,3)
               | FIELD_BUILD(RF_MIX_ENB_CAP,0);
   RF->REG08 = FIELD_BUILD(RF_LDO_RX_TRIM,4)
               | FIELD_BUILD(RF_LDO_TX_TRIM,4)
               | FIELD_BUILD(RF_CF_BW12M_ADJ,1)
               | FIELD_BUILD(RF_TX_RATE,0)
               | FIELD_BUILD(RF_CF_BW08M_ADJ,0)
               | FIELD_BUILD(RF_TX_DATA_TST_EN,0)
               | FIELD_BUILD(RF_PA_VCAS_RES_ADJ,1)
               | FIELD_BUILD(RF_PA_GAIN,0xf)
               | FIELD_BUILD(RF_PA_TANK_Q_ADJ,0)
               | FIELD_BUILD(RF_EN_PA_IBX2,0);
   RF->REG0C = FIELD_BUILD(RF_PA_TANK_TUNE,2)
               | FIELD_BUILD(RF_EN_RSSI_Q,0)
               | FIELD_BUILD(RF_EN_RSSI_I,0)
               | FIELD_BUILD(RF_PA_VB1_ADJ,0)
               | FIELD_BUILD(RF_PA_VB2_ADJ,0)
               | FIELD_BUILD(RF_PA_PTAT_ADJ,1)
               | FIELD_BUILD(RF_EN_PA_IPTAT,1)
               | FIELD_BUILD(RF_PA_BG_ADJ,4)
               | FIELD_BUILD(RF_EN_PA_IBG,1)
               | FIELD_BUILD(RF_PLL_BAND_CAL_SEL,0)
               | FIELD_BUILD(RF_PLL_AFC_FRAC_EN,0)
               | FIELD_BUILD(RF_PLL_AFC_DC_EN,0)
               | FIELD_BUILD(RF_PLL_VCTRL_EXT_EN,0)
               | FIELD_BUILD(RF_PLL_DIV_ADJ,2)
               | FIELD_BUILD(RF_PLL_SEL_RTX_BW,0);
   RF->REG10 = FIELD_BUILD(RF_PLL_DI_S,20)
               | FIELD_BUILD(RF_PLL_RTX_SEL,0)
               | FIELD_BUILD(RF_PLL_OPEN_EN,0)
               | FIELD_BUILD(RF_PLL_CAL_EN,0)
               | FIELD_BUILD(RF_PLL_FREQ_ADJ_EXT,0)
               | FIELD_BUILD(RF_PLL_FREQ_EXT_EN,0)
               | FIELD_BUILD(RF_PLL_FAST_LOCK_EN,1)
               | FIELD_BUILD(RF_PLL_REF_SEL,0)
               | FIELD_BUILD(RF_PLL_VREF_ADJ,0)
               | FIELD_BUILD(RF_PLL_FBDIV_PD_BYPS,0)
               | FIELD_BUILD(RF_PLL_BW_ADJ,2)
               | FIELD_BUILD(RF_PLL_LOCK_BYPS,0)
               | FIELD_BUILD(RF_PLL_CP_OS_ADJ,0)
               | FIELD_BUILD(RF_PLL_CP_OS_EN,0)
               | FIELD_BUILD(RF_PLL_VCO_ADJ,2);
   RF->REG14 = FIELD_BUILD(RF_PLL_FRAC,0)
               | FIELD_BUILD(RF_DAC_CAL_DATA_EXT,0)
               | FIELD_BUILD(RF_DAC_CAL_EN_EXT,0)
               | FIELD_BUILD(RF_DAC_EXT_EN,0)
               | FIELD_BUILD(RF_DAC_BLE_DELAY_ADJ,0x10);
   RF->REG18 = FIELD_BUILD(RF_DAC_REFL_ADJ,4)
               | FIELD_BUILD(RF_ADC_MUX_SEL,0)
               | FIELD_BUILD(RF_ADC_VREF_ADJ,0)
               | FIELD_BUILD(RF_ADC_TEST_SEL,0)
               | FIELD_BUILD(RF_EN_ADC_CNT_MODE,0)
               | FIELD_BUILD(RF_ADC_START,0);
   RF->REG1C = FIELD_BUILD(RF_EN_LDO_PLL_BYPS,0)
               | FIELD_BUILD(RF_EN_LDO_RX_BYPS,0)
               | FIELD_BUILD(RF_EN_LDO_TX_BYPS,0)
               | FIELD_BUILD(RF_EN_LDO_IF_BYPS,0)
               | FIELD_BUILD(RF_EN_LDO_PA_BYPS,0)
               | FIELD_BUILD(RF_EN_LDO_VCO_BYPS,0)
               | FIELD_BUILD(RF_ADC_REFBUF_LP,0)
               | FIELD_BUILD(RF_DAC_REFH_ADJ,1)
               | FIELD_BUILD(RF_PLL_DI_P,0x1f)
               | FIELD_BUILD(RF_PLL_FBDIV_PD,0)
               | FIELD_BUILD(RF_PLL_SDM_TEST_EN,0)
               | FIELD_BUILD(RF_PLL_FRAC_INT_MODE,0);
   RF->REG20 = FIELD_BUILD(RF_BPF_IADJ,4)
               | FIELD_BUILD(RF_BPF_BW_ADJ,1)
               | FIELD_BUILD(RF_BPF_MODE_SEL,0)
               | FIELD_BUILD(RF_BPF_CENT_ADJ,2)
               | FIELD_BUILD(RF_AT0_SEL,0xe)
               | FIELD_BUILD(RF_AT1_SEL,0xe);
   RF->REG24 = FIELD_BUILD(RF_AGC_S00L,8)
               | FIELD_BUILD(RF_AGC_S11_LNA_BYPS_ADJ,1)
               | FIELD_BUILD(RF_AGC_S10_LNA_BYPS_ADJ,1)
               | FIELD_BUILD(RF_AGC_S00H,0x2a)
               | FIELD_BUILD(RF_AGC_S01_MIX_ADJ,0)
               | FIELD_BUILD(RF_AGC_S01H,0x30)
               | FIELD_BUILD(RF_AGC_S10_MIX_ADJ,0x1) 
               | FIELD_BUILD(RF_AGC_S01L,0x1a)
               | FIELD_BUILD(RF_AGC_POWER_DET_EN,1)
               | FIELD_BUILD(RF_AGC_TEST_EN,0);
   RF->REG28 = FIELD_BUILD(RF_AGC_S10L,0x1d)
               | FIELD_BUILD(RF_AGC_S11_LNA_EN_ADJ,0)
               | FIELD_BUILD(RF_AGC_S10_LNA_EN_ADJ,0)
               | FIELD_BUILD(RF_AGC_S10_BPF_ADJ,1)
               | FIELD_BUILD(RF_AGC_T_ADJ,0)
               | FIELD_BUILD(RF_AGC_VH_ADD_ADJ,0)
               | FIELD_BUILD(RF_AGC_S01_BPF_ADJ,0)
               | FIELD_BUILD(RF_AGC_S11_BPF_ADJ,1)
               | FIELD_BUILD(RF_AGC_S00_BPF_ADJ,1)
               | FIELD_BUILD(RF_AGC_S11_MIX_ADJ,1)
               | FIELD_BUILD(RF_AGC_S00_MIX_ADJ,0)
               | FIELD_BUILD(RF_AGC_S11_LNA_ADJ,3)
               | FIELD_BUILD(RF_AGC_S10_LNA_ADJ,3)
               | FIELD_BUILD(RF_AGC_S01_LNA_ADJ,3)
               | FIELD_BUILD(RF_AGC_S00_LNA_ADJ,0);
   RF->REG2C = FIELD_BUILD(RF_PLL_GAIN_CAL_SEL,0)
               | FIELD_BUILD(RF_PLL_FBDIV_RST_SEL,0)
               | FIELD_BUILD(RF_PLL_FBDIV_RST_EXT,0)
               | FIELD_BUILD(RF_PLL_PS_CNT_RST_SEL,0)
               | FIELD_BUILD(RF_AGC_TEST_S,0)
               | FIELD_BUILD(RF_PA_MN_TUNE,2)
               | FIELD_BUILD(RF_PLL_GAIN_CAL_TH,0x64)
               | FIELD_BUILD(RF_PLL_VTXD_EXT,pll_int_vtxd_ext_24g)
               | FIELD_BUILD(RF_PLL_VTXD_EXT_EN,1)
               | FIELD_BUILD(RF_PLL_GAIN_CAL_EN,0)
               | FIELD_BUILD(RF_PLL_GAIN_CAL_DC,1);
   RF->REG30 = FIELD_BUILD(RF_RSV,0x44)
               | FIELD_BUILD(RF_LDO_PA_TRIM,7)
               | FIELD_BUILD(RF_EN_LMT_OUTI_EXT,1)
               | FIELD_BUILD(RF_EN_LMT_OUTQ_EXT,1)
               | FIELD_BUILD(RF_PAHP_SEL,1)
               | FIELD_BUILD(RF_LDO_PAHP_TRIM,0xf)
               | FIELD_BUILD(RF_EN_AT,0)
               | FIELD_BUILD(RF_PAHP_ADJ,0xf);
   RF->REG50 = FIELD_BUILD(RF_ANA_TEST_EN,0)
               | FIELD_BUILD(RF_PLL_AFC_BP,0)
               | FIELD_BUILD(RF_PLL_GAIN_BP,1)
               | FIELD_BUILD(RF_PPF_RC_BP,1)
               | FIELD_BUILD(RF_LDO_TEST_EN,0)
               | FIELD_BUILD(RF_RD_CLK_EN,1)
               | FIELD_BUILD(RF_PLL_TEST_EN,0)
               | FIELD_BUILD(RF_CH_SEL,1)
			   | FIELD_BUILD(RF_PA_VB_SEL,0)
			   | FIELD_BUILD(RF_PA_VB_TARGET,0)
               | FIELD_BUILD(RF_LDO_START_CNT,6)
			   | FIELD_BUILD(RF_PA_STEP_SET,8);
    RF->REG58 = FIELD_BUILD(RF_EN_DAC_CNT,10)
               | FIELD_BUILD(RF_PLL_CAL_EN_CNT,0x08)
               | FIELD_BUILD(RF_PLL_GAIN_CAL_EN_CNT,4)
               | FIELD_BUILD(RF_EN_PA_CNT,0x48);
    RF->REG5C = FIELD_BUILD(RF_EN_PA_STG1_CNT,0x4a)
               | FIELD_BUILD(RF_EN_PA_STG2_CNT,0x4c)
               | FIELD_BUILD(RF_PLL_LOCK_CNT,0x4f)
               | FIELD_BUILD(RF_EN_RX_CNT,2);
    RF->REG64 = FIELD_BUILD(RF_RSSI_OFFSET, 0X80)
                |FIELD_BUILD(RF_ADC_MDM_EN, 1);  
    RF->REG70 = FIELD_BUILD(RF_RX2MBW_FORCE_EN,0)
               | FIELD_BUILD(RF_INT_VTXD_CHN_THR1,0x19)
               | FIELD_BUILD(RF_INT_VTXD_CHN_THR0,0xc)
               | FIELD_BUILD(RF_INT_VTXD_EXT2,pll_int_vtxd_ext_24g)
               | FIELD_BUILD(RF_INT_VTXD_EXT1,pll_int_vtxd_ext_24g);
    REG_FIELD_WR(RF->REG50, RF_PLL_TEST_EN, 1);
}

void ls_24g_rf_tx_chn_setting(uint16_t tx_chn)
{ 
    REG_FIELD_WR(RF->REG1C, RF_PLL_DI_P, 0x1f);  // set DI_P to default value 31
    uint32_t tx_chn_frac = tx_frac_array[tx_chn - 2350];
    uint8_t tx_chn_dis = tx_di_s_array[tx_chn - 2350];
    REG_FIELD_WR(RF->REG50, RF_PLL_TEST_EN, 1);
    REG_FIELD_WR(RF->REG14, RF_PLL_FRAC, tx_chn_frac);
    REG_FIELD_WR(RF->REG10, RF_PLL_DI_S, tx_chn_dis);   
    REG_FIELD_WR(RF->REG10, RF_PLL_RTX_SEL, 1);
}

void ls_24g_rf_rx_chn_setting(uint16_t rx_chn)
{ 
    REG_FIELD_WR(RF->REG1C, RF_PLL_DI_P, 0x1f);  // set DI_P to default value 31
    uint32_t rx_chn_frac = rx_frac_array[rx_chn - 2350];
    uint8_t rx_chn_dis = rx_di_s_array[rx_chn - 2350];
    REG_FIELD_WR(RF->REG50, RF_PLL_TEST_EN, 1);  
    REG_FIELD_WR(RF->REG14, RF_PLL_FRAC, rx_chn_frac);
    REG_FIELD_WR(RF->REG10, RF_PLL_DI_S, rx_chn_dis);  
    REG_FIELD_WR(RF->REG10, RF_PLL_RTX_SEL, 0);
    if (rx_chn < 2370)
    {
        while(!(REG_FIELD_RD(RF->REG38,RF_PLL_BAND_CAL_DONE)));

        REG_FIELD_WR(RF->REG1C,RF_PLL_DI_P,0x1e);
        REG_FIELD_WR(RF->REG10, RF_PLL_DI_S, rx_chn_dis + 4);  
    }
}
void RF_24g_SetPower(enum prop_24g_tx_power_config tx_pwr_config)
{
    LS_ASSERT(tx_pwr_config < TX_POWER_MAX);
    if(tx_pwr_config == 7 || tx_pwr_config == 0xB)
    {
        REG_FIELD_WR(RF->REG00,RF_EN_PAHP,1);
        REG_FIELD_WR(RF->REG30,RF_PAHP_SEL,1);
        REG_FIELD_WR(RF->REG30,RF_LDO_PAHP_TRIM,0xf);
        REG_FIELD_WR(RF->REG30,RF_LDO_PA_TRIM,7);
    }
    else{
        REG_FIELD_WR(RF->REG00,RF_EN_PAHP,0);
        REG_FIELD_WR(RF->REG30,RF_PAHP_SEL,0);
        REG_FIELD_WR(RF->REG30,RF_LDO_PAHP_TRIM,0);
        REG_FIELD_WR(RF->REG30,RF_LDO_PA_TRIM,3);
    }

    REG_FIELD_WR(RF->REG50,RF_PA_VB_TARGET,tx_pwr_config);
}
static uint16_t rf_pll_gain_cal_24g(uint8_t tx_di_s, uint32_t tx_frac)
{
    uint8_t pll_gain_cal_val            =0;

    REG_FIELD_WR(RF->REG10, RF_PLL_RTX_SEL, 1);  
    REG_FIELD_WR(RF->REG1C, RF_PLL_FRAC_INT_MODE, 1);  //Integer mode

    REG_FIELD_WR(RF->REG14, RF_PLL_FRAC, tx_frac);
    REG_FIELD_WR(RF->REG10, RF_PLL_DI_S, tx_di_s); 
     
    //AFC 
    REG_FIELD_WR(RF->REG10,RF_PLL_VREF_ADJ,0);//vref_calib 
    REG_FIELD_WR(RF->REG10,RF_PLL_FREQ_EXT_EN,0);         
    REG_FIELD_WR(RF->REG10, RF_PLL_CAL_EN, 0);// AFC CAL disable
	REG_FIELD_WR(RF->REG10, RF_PLL_CAL_EN, 1);// AFC CAL enable

    while(!REG_FIELD_RD(RF->REG38,RF_PLL_BAND_CAL_DONE)); 

    // gain cal 
    REG_FIELD_WR(RF->REG00,RF_EN_DAC_BLE,1); 
    REG_FIELD_WR(RF->REG2C,RF_PLL_VTXD_EXT_EN,0); 
    REG_FIELD_WR(RF->REG2C,RF_PLL_GAIN_CAL_EN,0); 
    REG_FIELD_WR(RF->REG2C,RF_PLL_GAIN_CAL_EN,1);  

    while(!REG_FIELD_RD(RF->REG38,RF_PLL_GAIN_CAL_DONE));

    pll_gain_cal_val =REG_FIELD_RD(RF->REG38, RF_PLL_DAC_ADJ_TEST);
    REG_FIELD_WR(RF->REG2C,RF_PLL_VTXD_EXT_EN,1); 
    REG_FIELD_WR(RF->REG10, RF_PLL_CAL_EN, 0);
    REG_FIELD_WR(RF->REG2C,RF_PLL_GAIN_CAL_EN,0);
    REG_FIELD_WR(RF->REG1C, RF_PLL_FRAC_INT_MODE, 0);
    return pll_gain_cal_val;
}

void pll_gain_24g(uint16_t tx_chn)
{   
    LS_ASSERT(tx_chn >= 2370 && tx_chn <= 2510);
    uint32_t tx_chn_frac;
    uint8_t tx_chn_dis;

    tx_chn_frac = tx_frac_array[tx_chn - 2350];
    tx_chn_dis = tx_di_s_array[tx_chn - 2350]; 

    uint8_t pll_gain_cal_val=0;
    // AFE TEST mode enable
    REG_FIELD_WR(RF->REG50,RF_ANA_TEST_EN,1);
    REG_FIELD_WR(RF->REG50,RF_LDO_TEST_EN,1);
    REG_FIELD_WR(RF->REG50,RF_PLL_TEST_EN,1);
    //TX
    REG_FIELD_WR(RF->REG10,RF_PLL_RTX_SEL,1);
    REG_FIELD_WR(RF->REG00,RF_EN_PA,1);
    REG_FIELD_WR(RF->REG00,RF_EN_PA_STG1,1);
    REG_FIELD_WR(RF->REG00,RF_EN_PA_STG2,1);
    REG_FIELD_WR(RF->REG00,RF_EN_LDO_RX,0);

    pll_gain_cal_val = rf_pll_gain_cal_24g(tx_chn_dis, tx_chn_frac);
    pll_int_vtxd_ext_24g = pll_gain_cal_val; 

    // LOG_I("gain calib val: 0x%x", pll_int_vtxd_ext_24g);

    REG_FIELD_WR(RF->REG2C,RF_PLL_VTXD_EXT_EN,0);  
    REG_FIELD_WR(RF->REG2C,RF_PLL_VTXD_EXT,pll_int_vtxd_ext_24g);
    REG_FIELD_WR(RF->REG70,RF_INT_VTXD_EXT1,pll_int_vtxd_ext_24g);
    REG_FIELD_WR(RF->REG70,RF_INT_VTXD_EXT2,pll_int_vtxd_ext_24g);
    REG_FIELD_WR(RF->REG2C,RF_PLL_VTXD_EXT_EN,1);
    
    REG_FIELD_WR(RF->REG00,RF_EN_PA_STG2,0);
    REG_FIELD_WR(RF->REG00,RF_EN_PA_STG1,0);
    REG_FIELD_WR(RF->REG00,RF_EN_PA,0);
    REG_FIELD_WR(RF->REG00,RF_EN_LDO_RX,1);
    //AFE TEST mode disable
    REG_FIELD_WR(RF->REG50,RF_ANA_TEST_EN,0);
    REG_FIELD_WR(RF->REG50,RF_LDO_TEST_EN,0);
    REG_FIELD_WR(RF->REG50, RF_PLL_TEST_EN, 1);

}

static void modem_reg_init_24g(void)
{
    MDM2->REG08 = FIELD_BUILD(MDM2_MIN_MAG_CONF,0x474)
               | FIELD_BUILD(MDM2_DRIFT_COR_SET,1)
               | FIELD_BUILD(MDM2_IF_SHIFT,0x400);
    MDM2->REG20 = FIELD_BUILD(MDM2_LR_IF_SHIFT,0x400)
               | FIELD_BUILD(MDM2_LR_RX_INVERT,1)
               | FIELD_BUILD(MDM2_LR_IQ_INVERT,0)
               | FIELD_BUILD(MDM2_LR_ACC_INVERT,0);
}

static void rf_reg_retention_24g(void)
{
    // uint32_t rf_reg08 = RF->REG08;
    // rf_ret.ldo_tx_trim = REG_FIELD_RD(rf_reg08,RF_LDO_TX_TRIM);
    // rf_ret.ldo_rx_trim = REG_FIELD_RD(rf_reg08,RF_LDO_RX_TRIM);
}

int8_t rf_rssi_convert_24g(uint8_t rssi_reg)
{
    // LOG_I("rssi_reg: %d", rssi_reg);
    int8_t rssi_dbm;
    uint8_t agc_state;
    agc_state = REG_FIELD_RD(RF->REG6C,RF_AGC_STATE);
    if(agc_state ==2 ){
        rssi_dbm = rssi_reg-255 + agc_state*17 ;
    }
    else if(agc_state == 1){
        rssi_dbm = rssi_reg-255 + agc_state*6 ;
    }
    else{
        rssi_dbm = rssi_reg-255-20;
    }
    return (rssi_dbm);
}

static void modem_rf_reinit_24g(void)
{
    rf_reg_init_24g();
    modem_reg_init_24g();
}

void modem_rf_init_24g(void)
{
    RCC->APB1EN |= 1<<RCC_RF_POS | 1<<RCC_MDM2_POS;
    rf_reg_retention_24g();
    modem_rf_reinit_24g();
    // pll_gain_24g(2400);
}

void modem_rf_set_rx_phy(uint8_t phy)
{
    if (phy != PROP_24G_PHY_2MBPS)
    {
        REG_FIELD_WR(RF->REG08, RF_CF_BW12M_ADJ, PROP_24G_PHY_1MBPS);
    }
    else
    {
        REG_FIELD_WR(RF->REG08, RF_CF_BW12M_ADJ, PROP_24G_PHY_2MBPS);
    }
}
